class_name WeightTable

var items: Array[Dictionary] = []
var weight_sum = 0

func add_item(item, weight:int):
	if items.has({"item": item, "weight":weight}):
		print("已存在对应的敌人")
		return
	items.append({"item": item, "weight":weight})
	weight_sum += weight

func pick_item():
	var chosen_weight = randi_range(1, weight_sum)
	var iteration_sum = 0
	for i in items:
		iteration_sum += i["weight"]
		if chosen_weight <= iteration_sum:
			return i["item"]
			
